package com.woniu.woniu_bx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.woniu_bx.pojo.Goods;
import com.woniu.woniu_bx.pojo.GoodsCategory;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Auther: Ayang
 * @Date: 2022/8/27 16:09
 * @Description:
 */
@Repository
public interface GoodsCategoryMapper extends BaseMapper<GoodsCategory> {
    /**
     * 查找商品类别名的数量
     */
    @Select("select count(*) from bx_category where name = #{name}")
    Integer selectNum(String name);

    //根据OrderNumber查询
    @Select("select * from bx_category order by order_number")
    List<GoodsCategory> selectByOrderNumber();

    //模糊查询
    @Select("select * from bx_category where name like concat('%',#{name},'%') and nav =#{nav} and status =#{status}")
    List<GoodsCategory> selectByName(String name,String nav,String status);

    //锁定
    @Update("update bx_category set status = 'n' where id = #{id}")
    void lock(int id);

    //解锁
    @Update("update bx_category set status = 'y' where id = #{id}")
    void unlock(int id);

    //换位
    @Update("update bx_category bc1 join bx_category bc2 on (bc1.id=#{id1} and bc2.id=#{id2}) set bc1.order_number = bc2.order_number,bc2.order_number = bc1.order_number")
    void changeorderNumber(int id1,int id2);

    //通过序号查找
    @Select("select * from bx_category where order_number = #{ordernumber}")
    GoodsCategory findByOrderNumber(int orderNumber);

    //名称检查
    @Select("select * from bx_category where name = #{name}")
    GoodsCategory findByName(String name);

    //根据OrderNumber查询
    @Select("select * from bx_category where nav='y' and status = 'y' order by order_number")
    List<GoodsCategory> selectByOrderNumberReception();

    //根据类别查找商品
    @Select("select * from bx_goods bg where bg.category_id = #{id}")
    List<Goods> findByCategoryId(int id);

    @Select("select * from bx_category where id = #{id}")
    GoodsCategory findCategoryById(Integer id);
}
